#include <algorithm>
#include <cstdio>
const int N = 100001;
int n, m, heads[N], cnt, fa[N], top[N], siz[N], deep[N], son[N], tot, rt[N], qa[N], qb[N], qz[N];
struct Edge {
	int v, nxt;
} e[N << 1];
inline void add(int u, int v) {
	e[++cnt].nxt = heads[u];
	heads[u] = cnt;
	e[cnt].v = v;
}

void dfs1(int x) {
	siz[x] = 1;
	son[x] = 0;
	for (int i = heads[x]; i; i = e[i].nxt) {
		int v = e[i].v;
		if (fa[x] == v) continue;
		deep[v] = deep[x] + 1;
		fa[v] = x;
		dfs1(v);
		siz[x] += siz[v];
		if (siz[v] > siz[son[x]]) { son[x] = v; }
	}
}
void dfs2(int x) {
	if (son[x]) {
		top[son[x]] = top[x];
		dfs2(son[x]);
	}
	for (int i = heads[x]; i; i = e[i].nxt) {
		int v = e[i].v;
		if (fa[x] == v || v == son[x]) continue;
		top[v] = v;
		dfs2(v);
	}
}
inline int lca(int a, int b) {
	while (top[a] != top[b]) {
		if (deep[top[a]] < deep[top[b]]) std::swap(a, b);
		a = fa[top[a]];
	}
	if (deep[a] < deep[b]) std::swap(a, b);
	return b;
}
struct Node {
	int ls, rs, dat, id;
} tr[N << 6];
inline void pushup(int x) {
	if (tr[tr[x].ls].dat >= tr[tr[x].rs].dat) {
		tr[x].dat = tr[tr[x].ls].dat;
		tr[x].id = tr[tr[x].ls].id;
	} else {
		tr[x].dat = tr[tr[x].rs].dat;
		tr[x].id = tr[tr[x].rs].id;
	}
}
void modify(int &x, int l, int r, int val, int pos) {
	if (!x) { x = ++tot; }
	if (l == r) {
		tr[x].dat += val;
		tr[x].id = l;
		return;
	}
	int mid = (l + r) >> 1;
	if (pos <= mid)
		modify(tr[x].ls, l, mid, val, pos);
	else
		modify(tr[x].rs, mid + 1, r, val, pos);
	pushup(x);
}
int ans[N];
int merge(int x, int y, int l, int r) {
	if (!x) { return y; }
	if (!y) { return x; }
	if (l == r) {
		tr[x].dat += tr[y].dat;
		tr[x].id = l;
		return x;
	}
	int mid = (l + r) >> 1;
	tr[x].ls = merge(tr[x].ls, tr[y].ls, l, mid);
	tr[x].rs = merge(tr[x].rs, tr[y].rs, mid + 1, r);
	pushup(x);
	return x;
}
int maxr = 0;
void solve(int x) {
	for (int i = heads[x]; i; i = e[i].nxt) {
		if (e[i].v == fa[x]) continue;
		solve(e[i].v);
		rt[x] = merge(rt[x], rt[e[i].v], 1, maxr);
	}
	if (tr[rt[x]].dat) ans[x] = tr[rt[x]].id;
}
inline int max(int a, int b) { return a > b ? a : b; }
int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
	freopen("SegMerge.in", "r", stdin);
	freopen("SegMerge.out", "w", stdout);
#endif
#endif

	scanf("%d%d", &n, &m);
	int a, b;
	for (int i = 1; i < n; ++i) {
		scanf("%d%d", &a, &b);
		add(a, b);
		add(b, a);
	}
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d%d", &qa[i], &qb[i], &qz[i]);
		maxr = max(maxr, qz[i]);
	}
	deep[1] = 1;
	top[1] = 1;
	dfs1(1);
	dfs2(1);
	for (int i = 1; i <= m; ++i) {
		int mlca = lca(qa[i], qb[i]);
		modify(rt[qa[i]], 1, maxr, 1, qz[i]);
		modify(rt[qb[i]], 1, maxr, 1, qz[i]);
		modify(rt[mlca], 1, maxr, -1, qz[i]);
		if (fa[mlca]) modify(rt[fa[mlca]], 1, maxr, -1, qz[i]);
	}
	solve(1);
	for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
	return 0;
}